/*
 * @lc app=leetcode.cn id=384 lang=cpp
 *
 * [384] 打乱数组
 */

// @lc code=start
class Solution
{
public:
  vector<int> src;
  int n;

  Solution(vector<int>& nums)
  {
    this->src = nums;
    n = nums.size();
  }

  /** Resets the array to its original configuration and return it. */
  vector<int> reset()
  {
    return src;
  }

  /** Returns a random shuffling of the array. */
  vector<int> shuffle()
  {
    vector<int> ans(src.begin(), src.end());
    for (int i = 0; i < n; ++i) {
      int rand_idx = rand() % (i + 1);
      int tmp = ans[rand_idx];
      ans[rand_idx] = ans[i];
      ans[i] = tmp;
    }
    return ans;
  }
};

/**
 * Your Solution object will be instantiated and called as such:
 * Solution* obj = new Solution(nums);
 * vector<int> param_1 = obj->reset();
 * vector<int> param_2 = obj->shuffle();
 */
// @lc code=end
